package com.study.demo.controller;

import com.study.demo.exceptions.UserNotExistException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.Map;

/**
 * @author WS
 */
@Controller
public class HelloWorldController {
    @ResponseBody
    @GetMapping("/hello")
    public String hello(@RequestParam("id")String id) throws Exception {
        if("".equals(id)){
            throw new UserNotExistException();
        }
        return "Hello World!";
    }

    @RequestMapping("/success")
    public String success(Map<String,Object> map){
        map.put("hello","主页");
        map.put("head","<h1>这里是H1</h1>");
        map.put("users", Arrays.asList("张三","李四","王五"));
        return "success";
    }
}
